// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose:  Definition of the CXFormsElementCase class..
//   $Id$


// #ifndef CASEUI_H
// #define CASEUI_H 1

#pragma once
#include "XFormsElement.h"
#define CXFORMSELEMENTCASE_EVENTS_LENGTH 2
#define CASE_TOGGLES_BYREMOVING_ALL_CONTENT
typedef IDispatchImpl<IXFormsCaseElement, &IID_IXFormsCaseElement, &LIBID_XFORMSLib> CaseDispatch;
#include "EventTargetDispatch.h"
class CXFormsElementCase 
	: public CXFormsElement
	,public CaseDispatch
	,public CMultiIDispatch<CXFormsElementCase>
{
	friend HRESULT XFormsCaseInnerLoadContent(VOID ** ppArg);
public:
	CXFormsElementCase(void);
	~CXFormsElementCase(void);
	DECLARE_PROTECT_FINAL_CONSTRUCT()
	
	//COM interface declarations for script accessible methods
#pragma warning(disable:4244)
	BEGIN_MULTI_DISPATCH_MAP(CXFormsElementCase)
		MULTI_DISPATCH_ENTRY(CaseDispatch)
		MULTI_DISPATCH_ENTRY(EventTargetDispatch)
	END_MULTI_DISPATCH_MAP()
#pragma warning(default:4244)
STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames, \
                            LCID lcid, DISPID* rgdispid) \
	{ 
		if(m_bParseDone)
			return CMultiIDispatch<CXFormsElementCase>::GetIDsOfNames(riid, rgszNames, cNames, 
                                              lcid, rgdispid); 
			else
			{
				return DISP_E_UNKNOWNNAME;
			}

	};
   STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, \
                     LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, \
                     EXCEPINFO* pexcepinfo, UINT* puArgErr) \
	{ 
      return CMultiIDispatch<CXFormsElementCase>::Invoke(dispidMember, riid, lcid, wFlags, 
                                       pdispparams, pvarResult, 
                                       pexcepinfo, puArgErr); 
	}

	BEGIN_COM_MAP(CXFormsElementCase)
		COM_INTERFACE_ENTRY(IXFormsCaseElement)
		COM_INTERFACE_ENTRY2(IDispatch,IXFormsCaseElement)
		COM_INTERFACE_ENTRY_CHAIN(CXFormsElement)
	END_COM_MAP()

	virtual CImpl* CreateImpl();
	virtual CXFormsParse* CreateParse(CImpl* pImpl);
	HRESULT put_value(BSTR sValue);
	virtual HRESULT put_XPathExpression(const BSTR bsXPath);
	virtual HRESULT InitBehaviour(void);
	STDMETHOD(loadContent)();
	STDMETHOD(unloadContent)();
	STDMETHOD(toggle)();
#ifdef CASE_TOGGLES_BYREMOVING_ALL_CONTENT
	virtual HRESULT SelectedEffect();
	virtual HRESULT DeselectedEffect();
	HRESULT LoadContent();
	HRESULT UnloadContent();
#endif
	bool IsAppearanceFull();

protected:
	virtual HRESULT render();
	virtual void populateEvents(void);


private:
	//If the current case contains an active input, it may leave the caret behind on deselect.
	//	This makes it not do such a careless thing.
	HRESULT ConcealCaretIfWithinCurrentCase();
	//array storing event cookies.
	//	these are the ids given to us by 
	//	RegisterEvent.
	long m_alEventCookies[CXFORMSELEMENTCASE_EVENTS_LENGTH];
	//The event cookies are assigned on an
	//	object-by-object basis, however, 
	//	the names can be static.
	static const CComBSTR * const sm_asEventNames[CXFORMSELEMENTCASE_EVENTS_LENGTH];
	bool ToggleCaseByRemovingContent() const;
	bool m_bDeferredContentLoading;
	bool m_bContentLoaded;
	bool m_bParseDone;
};
// #endif // CASEUI_H
